"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.formatSecond = formatSecond;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _jsxRuntime = require("react/jsx-runtime");

var _antdV = require("antd-v4");

var _react = _interopRequireDefault(require("react"));

/**
 * 格式化秒
 *
 * @param result
 * @returns {string}
 */
function formatSecond(result) {
  var formatText = '';
  var d = Math.floor(result / (3600 * 24));
  var h = Math.floor(result / 3600);
  var m = Math.floor(result / 60 % 60);
  var s = Math.floor(result % 60);
  formatText = "".concat(s, "\u79D2");

  if (m > 0) {
    formatText = "".concat(m, "\u5206\u949F").concat(formatText);
  }

  if (h > 0) {
    formatText = "".concat(h, "\u5C0F\u65F6").concat(formatText);
  }

  if (d > 0) {
    formatText = "".concat(d, "\u5929").concat(formatText);
  }

  return formatText;
}
/**
 * 格式化秒
 *
 * @param FieldSecond
 */


var Second = function Second(_ref, ref) {
  var text = _ref.text,
      type = _ref.mode,
      render = _ref.render,
      renderFormItem = _ref.renderFormItem,
      fieldProps = _ref.fieldProps,
      placeholder = _ref.placeholder;

  if (type === 'read') {
    var secondText = formatSecond(Number(text));
    var dom = (0, _jsxRuntime.jsx)("span", {
      ref: ref,
      children: secondText
    });

    if (render) {
      return render(text, (0, _objectSpread2.default)({
        mode: type
      }, fieldProps), dom);
    }

    return dom;
  }

  if (type === 'edit' || type === 'update') {
    var _dom = (0, _jsxRuntime.jsx)(_antdV.InputNumber, (0, _objectSpread2.default)({
      ref: ref,
      min: 0,
      style: {
        width: '100%'
      },
      placeholder: placeholder
    }, fieldProps));

    if (renderFormItem) {
      return renderFormItem(text, (0, _objectSpread2.default)({
        mode: type
      }, fieldProps), _dom);
    }

    return _dom;
  }

  return null;
};

var _default = /*#__PURE__*/_react.default.forwardRef(Second);

exports.default = _default;